﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using Microsoft.Xna.Framework.Storage;

namespace GalconGame.Database
{
    class Serializable
    {
        StorageContainer container;

        public Serializable() 
        {
            createStorageContainer();
        }

        public void createStorageContainer()
        {

        }

        public void saveFile(Object data, string fileName)
        {
            // Open the file, creating it if necessary
            FileStream stream =  File.Open(fileName, FileMode.OpenOrCreate);
            try
            {
                // Convert the object to XML data and put it in the stream
                XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
                serializer.Serialize(stream, data);
            }
            finally
            {
                // Close the file
                stream.Close();
            }

        }

        public Object loadFile(string fileName)
        {
            Object data;
            // Open the file
            FileStream stream = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Read);
            try
            {

                // Read the data from the file
                XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
                data = (HighScoreData)serializer.Deserialize(stream);
            }
            finally
            {
                // Close the file
                stream.Close();
            }

            return (data);
        }
    }
}
